home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / PowerD / powerd / examples / fractal / mandelbrotreq.d < prev    next >
Encoding:
Text File  |  2002-10-28  |  2.5 KB  |  79 lines

  1. // Mandelbrot fractal by Robert Kihl (robert@snarl-up.com)
  2.  
  3.  
  4. MODULE  'dos/dos','exec/memory','intuition/intuition','intuition/screens',
  5.         'graphics/modeid','utility/tagitem','asl','libraries/asl'
  6.  
  7. DEF ASLBase
  8.  
  9. PROC main()
  10.   DEFW w=320,h=240,d=8,x,y=0,n,iters
  11.   DEFF zp,zq,cp,cq,xstep,ystep,xmin=-2.0,xmax=0.8,ymin=-1.2,ymax=1.2,ftemp
  12.   DEF screen:PTR TO Screen,window:PTR TO Window,vp
  13.   DEF asl:PTR TO ScreenModeRequester
  14.  
  15.   IF ASLBase:=OpenLibrary('asl.library',37)
  16.  
  17.     IF asl:=AllocAslRequest(ASL_ScreenModeRequest, NIL)
  18.  
  19.       IF AslRequest(asl, NIL)
  20.  
  21.         IF screen:=OpenScreenTags(NIL, SA_Width,asl.DisplayWidth,
  22.                                        SA_Height,asl.DisplayHeight,
  23.                                        SA_Depth,8,
  24.                                        SA_Title,'Mandelbrot',
  25.                                        SA_DisplayID,asl.DisplayID,
  26.                                        TAG_END)
  27.  
  28.           IF window:=OpenWindowTags(NIL, WA_Width,asl.DisplayWidth,
  29.                                          WA_Height,asl.DisplayHeight,
  30.                                          WA_IDCMP,IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS,
  31.                                          WA_Flags,WFLG_BORDERLESS|WFLG_ACTIVATE|WFLG_RMBTRAP,
  32.                                          WA_CustomScreen,screen,
  33.                                          TAG_END)
  34.  
  35.             vp:=ViewPortAddress(window)
  36.             FOR n:=0 TO 255 DO SetRGB32(vp,n,n<<20,n<<23,n<<24)
  37.  
  38.             xstep:=(xmax-xmin)/asl.DisplayWidth
  39.             ystep:=(ymax-ymin)/asl.DisplayHeight
  40.  
  41.  
  42.             FOR cq:=ymin TO ymax STEP ystep
  43.               x:=0
  44.               FOR cp:=xmin TO xmax STEP xstep
  45.                 iters:=0
  46.                 zp:=0
  47.                 zq:=0
  48.                 WHILE FAbs(zp)<4 AND iters<96
  49.                   ftemp:=zp*zp-zq*zq+cp
  50.                   zq:=2*(zp*zq)+cq
  51.                   zp:=ftemp
  52.                   iters++
  53.                 ENDWHILE
  54.                 SetAPen(window.RPort,192-iters*2)
  55.                 WritePixel(window.RPort,x,y)
  56.                 x++
  57.                 IF Mouse() THEN cq:=ymax
  58.               ENDFOR
  59.               y++
  60.             ENDFOR
  61.  
  62.             WaitPort(window.UserPort)
  63.             CloseWindow(window)
  64.             FreeAslRequest(asl)
  65.  
  66.           ELSE PrintF('Unable to open window\n')
  67.  
  68.           CloseScreen(screen)
  69.  
  70.         ELSE PrintF('Unable to open screen\n')
  71.  
  72.       ELSE PrintF('Unable to open aslrequester\n')
  73.  
  74.     ELSE PrintF('Unable to Allocate aslrequester\n')
  75.  
  76.   ELSE PrintF('Unable to open asl.library\n')
  77.  
  78. ENDPROC
  79.